/*
 * @Author: leemr lscmr@qq.com
 * @Date: 2023-12-25 18:23:10
 * @LastEditors: leemr lscmr@qq.com
 * @LastEditTime: 2023-12-25 18:26:33
 * @FilePath: \futures-bill\src\utils\wxfont.ts
 * @Description:
 *
 */
//增加meta标签，禁止调整字体大小
function createMetaTag(name:string, content:string) {
  const metaTag = document.createElement('meta');
  metaTag.setAttribute('name', name);
  metaTag.setAttribute('content', content);
  return metaTag;
}

// 添加 viewport meta 标签
const viewportMeta = createMetaTag('viewport', 'width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no');
document.head.appendChild(viewportMeta);

// 添加 wap-font-scale meta 标签
const fontScaleMeta = createMetaTag('wap-font-scale', 'no');
document.head.appendChild(fontScaleMeta);

// 添加处理字体大小的 JavaScript 代码
(function () {
  if (typeof WeixinJSBridge == "object" && typeof WeixinJSBridge.invoke == "function") {
    handleFontSize();
  } else {
    if (document.addEventListener) {
      document.addEventListener("WeixinJSBridgeReady", handleFontSize, false);
    } else if (document.attachEvent) {
      document.attachEvent("WeixinJSBridgeReady", handleFontSize);
      document.attachEvent("onWeixinJSBridgeReady", handleFontSize);
    }
  }
  function handleFontSize() {
    // 设置网页字体为默认大小
    WeixinJSBridge.invoke('setFontSizeCallback', { 'fontSize': 0 });
    // 重写设置网页字体大小的事件
    WeixinJSBridge.on('menu:setfont', function () {
      WeixinJSBridge.invoke('setFontSizeCallback', { 'fontSize': 0 });
    });
  }
})();
